import { Player } from "@/core/playersystem/player";
import { BrilliantCard } from "../card";


export class DelayBrilliantness extends BrilliantCard {

    onDrop(): void {
        if (this.cardProperties.target) {
            this.cardProperties.target.judgeAreaController.removeFromJudgeArea(this)
        }
        super.onDrop()
    }

    async use(): Promise<void> {
        if (this.cardProperties.owner) {
            if (!this.cardProperties.source) {
                this.cardProperties.source = this.cardProperties.owner
            }
            if (!this.cardProperties.target) {
                await this.waitforSpecTarget(this.cardProperties.source)
            }

            if (this.cardProperties.target) {
                this.cardProperties.target.judgeAreaController.pushToJudgeArea(this)
                this.cardProperties.source.handCardAreas.dropCard(this)
            }
        }
    }

    async waitforSpecTarget(source: Player): Promise<void> {

    }


    /**
     * 简要
     * @returns 
     */
    brief(): string {
        return ""
    }

    executeEffect() {

    }

}

/**
 * 乐不思蜀
 */
export class LeBuSiShu extends DelayBrilliantness {

    async waitforSpecTarget(source: Player): Promise<void> {
        let targetPlayer = this.cardProperties.target
        const gm = source.gameManager
        // 如果目标已经被指定了就不用再选玩家了
        if (targetPlayer == null) {
            const maxdistance = this.specDistance(source)
            let candidatePlayers = gm.distanceN(maxdistance)
            const pickNumber = 1
            candidatePlayers = candidatePlayers.filter(p => p.judgeAreaController.canPushJudgeArea(this))
            gm.appendLog(`${source.name} 打出了${this.colorCN()}${this.numberCN()}${this.info()} 请选择需要乐的玩家`)
            const options = {canPickPlayers: candidatePlayers, canPickMin: pickNumber, canPickMax: pickNumber, currentPlayer: source}

            const pickResult = await source.behaviorStragy.waitForPickPlayer(options)
            if (pickResult.cancel || pickResult.selectedPlayers.length < 1) {
                targetPlayer = null
            } else {
                targetPlayer = pickResult.selectedPlayers[0]
            }
            this.cardProperties.target = targetPlayer
        }
    }

    info(): string {
        return "乐不思蜀"
    }

    brief(): string {
        return "乐"
    }

}
